var mois = new Array('janvier', 'f&eacute;vrier', 'mars', 'avril', 'mai', 'juin', 'juillet', 'ao&ucirc;t', 'septembre', 'octobre', 'novembre', 'd&eacute;cembre');
var STATIC_URL_JS = "";

var homeTabsAndUrls = [
        'Home',//add in title
        ['/betrooms/', 'Betrooms'],//[ url, tab name]
        ['/help/', 'Rules'],
        ['/settings/', 'Settings'],
        ['/rules/', 'Document'],
        ['http://www.google.fr/', 'Google']
    ]; 
	
var createBetroomTabsAndUrls = [
	    'Creating ',//add in title
	    ['/betrooms/','Betrooms'],//[display, url, tab name]
	    ['/createBetroom/step2/','Betroom info'],//[url, tab name]
	    ['/createBetroom/step3/','Assets info'],//[url, tab name]
	    ['/createBetroom/step4/','Make your own bet'],//[url, tab name]
	    ['/createBetroom/step5/','Launch or delete']
	];
	
var probaMktTabsAndUrls = [
	    '',//add in title
	    ['javascript:leavPageToURLWithoutWaiting(\'/betrooms/\');','Betrooms'],//[url, tab name]
	    ['javascript:leavPageToURLWithoutWaiting(\'/market/\');','Market'],//[url, tab name]
	    ['javascript:leavPageToURLWithoutWaiting(\'/strategies/\');','My bet'],
	    ['javascript:leavPageToURLWithoutWaiting(\'/portfolio/\');','Portfolio and ranking'],
	    ['javascript:leavPageToURLWithoutWaiting(\'/derivatives/\');','Derivatives']
	];
	
var contractMktTabsAndUrls = [
	    '',//add in title
	    ['javascript:leavPageToURLWithoutWaiting(\'/betrooms/\');','Betrooms'],//[url, tab name]
	    ['javascript:leavPageToURLWithoutWaiting(\'/market/\');','Market'],//[url, tab name]
	    ['javascript:leavPageToURLWithoutWaiting(\'/newContract/\');','New contract'],
	    ['javascript:leavPageToURLWithoutWaiting(\'/portfolio/\');','Portfolio and ranking'],
	    ['javascript:leavPageToURLWithoutWaiting(\'/derivatives/\');','Derivatives']
	];
	
var adminMktTabsAndUrls = [
	    'ADMIN FOR ',//add in title
	    ['/betrooms/','Betrooms'],//[display, url, tab name]
	    ['/admin2/','Admin home'],
	    ['/admin2/saveAndCreateAdmin/','Save and create'],
	    ['/admin2/deleteAssetAdmin/','Delete asset'],
	    ['/admin2/addPlayerAdmin/','Add player']
	];
	

//--------------------------------------------------------------------------------------
function makeHeader( setOfPages, tabIndex, playerName, betroomName, roomType, status, STATIC_URL_str )
{
    STATIC_URL_JS = STATIC_URL_str;
    var statusStr = '';
    if( status < 1 )
    {
        statusStr = ' (being launched)';
    }
    if( status == -1 && setOfPages == 'createBetRoom' )
    {
        statusStr = ' (assets need validation)';
    }
    if( status == 2 )
    {
        statusStr = ' (suspended)';
    }
    
    // get the correct array
    var arrayLoc;
    if( setOfPages == 'home' ) {
		arrayLoc = homeTabsAndUrls;
	}else if( setOfPages == 'createBetroom' ) {
		arrayLoc = createBetroomTabsAndUrls;
	}else if( setOfPages == 'probaMkt' ) {
		arrayLoc = probaMktTabsAndUrls;
	}else if( setOfPages == 'contractMkt' ) {
		arrayLoc = contractMktTabsAndUrls;
	}else if( setOfPages == 'adminMkt' ) {
		arrayLoc = adminMktTabsAndUrls;
	}else{
		alert('Unexpected set of pages: '+setOfPages );
	}
	
	// add the banner
    var myVar = '<div class="header">' 
        + '<div class="myTab myTitle">'
        + '     <div class="myTitle_Header">'
        + '         <div class="myName">'+ arrayLoc[0]+betroomName+'</div>'
        + '         <div class="myStransacetionStatus">'+statusStr+'</div>'
        + '     </div>'
        + '     <div class="myTitle_footer">'
        + '	        <div class="myLeft"> logged as - '+playerName +'</div>'
        + '	        <div class="myRight"><a href="/logoutView/">logout</a> </div>'
        + '     </div>'
        + '</div>';
     // add the tabs
     for( var tab = 1; tab <= 5; ++tab ) {
		// in case of create betroom with typeroom =1, we do not display tab 2, 3, and 4
		if( setOfPages != 'createBetroom' || roomType == 0 || tab == 1 || tab == 5 ) {
		    var theUrl = arrayLoc[tab][0];
		    var theTitle = arrayLoc[tab][1];
		    if( roomType == 1 && theTitle == 'Delete asset' )
		    {
		        theUrl = '/admin2/settleContractView/';
		        theTitle = 'Settle contract';   
		    }
		    var tmp = '<div  id="id_tab'+tab+'" class="myTab tabN'+tab+'">';
		    tmp += '<a class="menu" href="'+theUrl+'">'+theTitle+'</a></div>'
			myVar += tmp;
		}
     }
    myVar += '</div>';
    document.write(myVar);
    $('#id_tab'+tabIndex).addClass('selectedTab')
};


//--------------------------------------------------------------------------------------
function footer()
{
    modDate = new Date(document.lastModified)
    dateTxt = modDate.getDate() +' ' + mois[modDate.getMonth()] + ' ' + modDate.getFullYear();
    document.write('<p class=myFooter>&copy; Celibax - ' + dateTxt + '</p>');
};



//--------------------------------------------------------------------------------------
// CSS property tester
function getCSS(e, p)
{
    var prop = "";
    if(e.currentStyle)
    {
        prop = e.currentStyle[p];
    }
    else if(window.getComputedStyle)
    {
        prop = document.defaultView.getComputedStyle(e,null).getPropertyValue(p);
    }
    return prop;
};



//--------------------------------------------------------------------------------------
// Attach PIE to all elements having a CSS3 property
function attachCSS3Properties()
{
    if(window.PIE)
    {
        for (i = document.all.length; i--; )
        {
            e = document.all[i];
            if ((getCSS(e, 'border-radius') != undefined && getCSS(e, 'border-radius') != "0px" ) // For IE < 9, border-radius, if not set, is undefined, for IE >= 9 it's "0px"
            || ( getCSS(e, 'box-shadow') != undefined && getCSS(e, 'box-shadow') != "none" )      // For IE < 9, box-shadow, if not set, is undefined, for IE >= 9 it's "none"
            || getCSS(e, '-pie-background') != undefined )                                        // For all IE, -pie-background, if not set, is undefined (except IE6, still to fix)
            {
                // alert("ok"); // Uncomment this line to be sure we do only 6 PIE.attach
                PIE.attach(e);
            }
        }
    }
};
